//以iphone6屏幕为标准的适配方法
function getPxAutoWidth(px) {
    var positionWidth = 375;
    var width = window.innerWidth;
    var v1 = px/positionWidth*width;
    return v1+"px";
}
function getPXAutoHeight(px) {
    var positionHeight = 667;
    var height = window.innerHeight;
    var v1 = px/positionHeight*height;
    return v1+"px";
}
//时间戳格式化 Y-M-D
function formateDate(timeStrmp) {
    var date = new Date(parseFloat(timeStrmp));
    Y = date.getFullYear() + '-';
    M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    D = date.getDate() + ' ';
    h = date.getHours() + ':';
    m = date.getMinutes() + ':';
    s = date.getSeconds();
    return Y+M+D;
}
//每三个字符间添加空格
function addCenterSpace(v) {
    return v.replace(/\s/g, '').replace(/(.{3})/g, "$1 ");
}
function hidePhone(phone) {
    phone = phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
    return phone;

}
//读取json文件
function getJsonData(url,callBack) {
    jq.getJSON(url,function (data) {
        console.info(data);
        return callBack(data["data"]);
    })
}
//获取json的外层key值
function getJsonKeys(v) {
    var arr = new Array();
    index = 0;
    for(var item in v){
        arr[index] = item;
        index ++;
    }
    return arr;
}
//获取请求url中的附加参数
function getParams() {
    var arr = window.location.href.split("?");
    var params = new Array();
    if (arr.length>1){
        var str = arr[1];
        jq(str.split("&")).each(function () {
            var param = this.split("=");
            params[param[0]] = param[1];
        });
    }
    return params;
}
//str转json
function strToJson(str){
    var json = (new Function("return " + str))();
    return json;
}

var jqq=jQuery.noConflict();
var loading_w = 32;
function loadingInit(imgPath) {
    jqq(document).ready(function(){
        jqq('body').append('<div class="loading" onclick="javascript:loading();" style="background-color:rgba(0,0,0,0.7);position: fixed;top:0;z-index: 1000;background:rgba(0,0,0,0.7);width: 100%;height: 100%;text-align: center;  display: none;"><img src="'+imgPath+'" style="width: '+loading_w+'px;"></div>')
    });
}
//loading
function startLoading() {
    var v = jqq('.loading').css('display');
    if (v == "none"){
        jqq('.loading img').css('margin-top',(jqq(window).height()/2-loading_w/2)+'px');
        jqq('.loading').css('display','block');
        //监听浏览器窗口变化
        window.onresize=function(){
            console.info(jqq(window).height());
            jqq('.loading img').css('line-height',(jqq(window).height()/2-15)+'px');
        }
    }
}
function stopLoading() {
    var v = jqq('.loading').css('display');
    if (v == "block"){
        jqq('.loading').css('display','none');
    }
}
